package com.example.assignment01_javaee.Controller;

import com.example.assignment01_javaee.Entity.Inventory;
import com.example.assignment01_javaee.Service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;

    @GetMapping("/inventory")
    public ResponseEntity<List<Inventory>> getAllInventory() {
        List<Inventory> inventoryList = inventoryService.getAllInventories();
        return ResponseEntity.ok(inventoryList);
    }

    @GetMapping("/inventory/{productId}")
    public ResponseEntity<Inventory> getInventoryByProductId(@PathVariable int productId) {
        Inventory inventory = inventoryService.getInventoryByProductId(productId);
        return ResponseEntity.ok(inventory);
    }

    @PutMapping("/inventory/{productId}")
    public String updateInventoryById(@PathVariable int productId, @RequestParam int quantity) {
        return inventoryService.updateInventoryById(productId,quantity);
    }

}
